package cn.seecoder.ai.controller;

import cn.seecoder.ai.enums.AnalysisFunctionEnum;
import cn.seecoder.ai.model.vo.AnalysisVisualizationVO;
import cn.seecoder.ai.model.vo.ResultVO;
import cn.seecoder.ai.service.AnalysisVisualizeService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DingXiaoyu
 * @date 2023/4/13 14:41
 */
@Slf4j
@RestController
@RequestMapping("${apiPrefix}/analysis/visualize")
public class AnalysisVisualizeController {

    @Autowired
    AnalysisVisualizeService analysisVisualizeService;

    @ApiOperation("可视化分析")
    @PostMapping("/{configId}")
    public ResultVO<AnalysisVisualizationVO> visualize(@PathVariable(value = "configId")Integer configId,
                                                       @RequestParam(value = "userId")Integer userId,
                                                       @RequestParam(value = "func") AnalysisFunctionEnum func){
        try {
            return ResultVO.buildSuccess(analysisVisualizeService.visualize(configId,userId,func));
        }catch (Exception e){
            return ResultVO.buildFailure("选择特征列数量或者类型错误");
        }

    }

    @ApiOperation("获取历史分析")
    @GetMapping("/{configId}")
    public ResultVO<List<AnalysisVisualizationVO>> getVisualization(@PathVariable(value = "configId")Integer configId,
                                                                    @RequestParam(value = "userId")Integer userId){
        return ResultVO.buildSuccess(analysisVisualizeService.getVisualization(configId,userId));
    }
}
